/**
 * Created by Administrator on 2015/6/5 0005.
 */
$(function() {
    // the widget definition, where "custom" is the namespace,
    // "colorize" the widget name
    $.widget( "thinkboot.navmenu", {
        // default options
        options: {
            url: null
        },

        // the constructor
        _create: function() {
            //this.text(this.options.url);
            //this.text(this.options.url);
            var self=this;

            $.ajax({
                type: 'POST',
                url:self.options.url,
                cache: false,
                beforeSend:function(){
                    self.element.addClass("nav nav-list");
                    self.element.text("loading......");
                },
                success:function(data){
                    self.element.text("");
                    $.each(data, function(i, menu) {
                        var li=$("<li></li>");
                        if(i==0){
                            li.addClass("active");
                        }
                        li.append($("<a href='#'></a>").append('<i class="icon-dashboard"></i>').append('<span class="menu-text"> '+menu.name+' </span>'));
                        self.getsubmenu(menu.son,li);

                        self.element.append(li);
                    });

                }
            });

        },
        getsubmenu:function(data,li){
            var self = this;
            if(data){
                li.find("a").addClass("dropdown-toggle");
                li.find("a").append('<b class="arrow icon-angle-down"></b>');
                li.append($('<ul class="submenu"></ul>'));
                $.each(data, function(j, submenu) {
                    var subli=$("<li></li>");

                    subli.append("<a href='"+submenu.url+"'></a>");
                    subli.find("a").append('<i class="icon-double-angle-right"></i>'+submenu.text);
                    li.find("ul").append(subli);
                    self.getsubmenu(data.son,li);
                });
            }
        }


    });

    //tabs


    // initialize with default options



});
